# -*- coding:utf-8 -*-

__author__ = '作者'

from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TCompactProtocol
from py.thrift.generated import PersonService, ttypes

try:
    tSocket = TSocket.TSocket('localhost', 8899)
    tSocket.setTimeout(600)

    transport = TTransport.TFramedTransport(tSocket)
    protocol = TCompactProtocol.TCompactProtocol(transport)

    client = PersonService.Client(protocol)
    transport.open()

    person = client.getPersonByUsername("王五")

    print(person.username)
    print(person.age)

    newPerson = ttypes.Person()
    newPerson.username = '李四'
    newPerson.age = 30

    client.savePerson(newPerson)

    transport.close()


except Thrift.TException as tx:
    print(tx.message)
